package com.bear.demo1;

import lombok.extern.slf4j.Slf4j;

import static java.lang.Thread.sleep;

/**
 * @author LiuShanshan
 * @version V1.0
 * @Description
 */
@Slf4j
public class JoinAndSleep {

    static int r1 = 0;
    static int r2 = 0;
    public static void main(String[] args) throws InterruptedException {
        test2();
    }
    private static void test2() throws InterruptedException {
        Thread t1 = new Thread(() -> {
            try {
                sleep(1000);
            }catch (Exception e){}
            r1 = 10;
        });
        Thread t2 = new Thread(() -> {
            try {
                sleep(2000);
            }catch (Exception e){}
            r2 = 20;
        });
        long start = System.currentTimeMillis();
        t1.start();
        t2.start();
        t1.join();
//        t2.join();
        long end = System.currentTimeMillis();
        System.out.println("r1和r2:" +r1 + " " + r2);
        System.out.printf("总共花费时间：" + (end-start));
//        log.debug("r1: {} r2: {} cost: {}", r1, r2, end - start);

    }
}
